/* dynload.c : dgnsc dynamic load dll
 * Copyright (C) 2009-2010 drangon <drangon.zhou@gmail.com>
 * 2009-05
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <dgnsc/dynload.h>

#ifdef _WIN32
#include <windows.h>
#else
#include <dlfcn.h>
#endif

dgn_dynload_t dgn_dynload_init( const char * so_name )
{
#ifdef _WIN32
	HMODULE hdl = LoadLibrary( so_name );
	return (dgn_dynload_t)hdl;
#else
	void * hdl = dlopen( so_name, RTLD_NOW | RTLD_GLOBAL );
	return hdl;
#endif
}

void * dgn_dynload_symbol( dgn_dynload_t dl, const char * symbol )
{
#ifdef _WIN32
	return GetProcAddress( (HMODULE)dl, symbol );
#else
	return dlsym( dl, symbol );
#endif
}

void dgn_dynload_fini( dgn_dynload_t dl )
{
#ifdef _WIN32
	FreeLibrary( (HMODULE)dl );
#else
	dlclose( dl );
#endif
	return;
}

